﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _Linq表达式调用方法
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Person> persons = new List<Person>()
            {
                new Person(){Id=1,Name = "张三",Birthday = DateTime.Now.AddYears(-22),CourseType = 1},
                new Person(){ Id=3,Name = "李四",Birthday = DateTime.Now.AddYears(-20), CourseType = 2},
                new Person(){ Id=3,Name = "王五",Birthday = DateTime.Now.AddYears(-15),CourseType = 3}
            };

            //先把数据放进内存当中就可以执行自定义方法了。

            var data = (from a in persons
                        select new
                        {
                            Name = a.Name,
                            Age = DateTime.Now.Year - a.Birthday.Year,
                            CourseType = GetCourseContent(a.CourseType)
                        }).ToList();

            foreach (var d in data)
            {
                Console.WriteLine(d.Name + "," + d.Age + "," + d.CourseType);
            }

            Console.ReadKey();
        }

        public static string GetCourseContent(int courseType)
        {
            string content = string.Empty;
            switch (courseType)
            {
                case 1: content = "大学生"; break;
                case 2: content = "高中生"; break;
                case 3: content = "初中生"; break;
                default: content = string.Empty; break;

            }

            return content;
        }
    }


    public class Person
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public DateTime Birthday { get; set; }

        public int CourseType { get; set; }
    }
}
